﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Edu.Web.Data.DV;
using Edu.Web.Data.Entity;

namespace Edu.Web.Data.DAO.Impl
{
    public partial class ApplyDAO
    {
        public IQueryable<ApplyDV> GetApplyList()
        {
            return from apply in Db.Set<ApplyEntity>()
                   join stu in Db.Set<UserEntity>() on apply.ApplyUserId equals stu.Id
                   join teacher in Db.Set<UserEntity>() on apply.ApproveUserId equals teacher.Id into t
                   from ti in t.DefaultIfEmpty()
                   orderby apply.ApplyTime descending
                   select new ApplyDV
                   {
                       ApplyEndTime = apply.ApplyEndTime,
                       ApplyTime = apply.ApplyTime,

                       ApplyRealName = stu.RealName,
                       ApplyRemark = apply.ApplyRemark,
                       ApplyStartTime = apply.ApplyStartTime,
                       ApplyType = apply.ApplyType,
                       ApplyUserId = apply.ApplyUserId,
                       ApproveUserId = apply.ApproveUserId,
                       ApproveRealName = ti == null ? "" : ti.RealName,
                       Id = apply.Id,
                       Status = apply.Status,
                       StatusTime = apply.StatusTime,
                       Title = apply.Title,
                       ApproveRemark=apply.ApproveRemark
                   };
        }
    }
}